package cz.incad.psh.pshassign.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiConstructor;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.FocusPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.Widget;
import cz.incad.psh.pshassign.client.json.ResultDoc;

/**
 *
 * @author Alberto Hernandez
 */
public class ResultBox extends Composite {

    private static ResultBoxUiBinder uiBinder = GWT.create(ResultBoxUiBinder.class);
    @UiField
    FocusPanel box;
    @UiField
    FlowPanel content;
    ResultDoc result;

    interface ResultBoxUiBinder extends UiBinder<Widget, ResultBox> {
    }

    @UiConstructor
    public ResultBox(ResultDoc r) {
        initWidget(uiBinder.createAndBindUi(this));
        this.result = r;
        content.add(new Label(r.getTitle()));
        content.setTitle(r.getId());

        box.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                MainPage mainPage = (MainPage) RootLayoutPanel.get().getWidget(0);
                mainPage.getPSHKeys(result.getId());
                mainPage.selectResult(box);
            }
        });
    }
}
